vFirstLoad = false
function ccR_Frame_OnEvent(self, event, ...)
	if event == "ADDON_LOADED" then
		ccR.Sys.Copy_Default_Settings(ccR_Default, ccR_Settings)
		ccR.Sys.Default()
		ccR.Sys.CactuaR.Load()
		if FireHack and not vFirstLoad then
			vFirstLoad = true
			ccR.Sys.Load.Initialize()
			if ccR.Var("Player_Features_Delay") ~= nil then
				ccR_Timer.Register('ccR_Player_Features', ccR.Player.Features, ccR.Var("Player_Features_Delay"))
			else
				ccR_Timer.Register('ccR_Player_Features', ccR.Player.Features, 0.5)
			end
			-- Empty Rotation, Set to 1st on list
			if ccR.Var("Rotation") == "Empty" and # DDM_List > 0 then UIDropDownMenu_SetSelectedID(DDM, 1) ccR.Var("Rotation", DDM_List[1])	end
			ccR.Sys.PrintToChat("Loaded!")
		else
			ccR.Sys.PrintToChat("Waiting for FireHack before loading files.")		
		end
		ccR_MinimapButton_Reposition()
		-- Tooltip Frame
		if not ccRTT then
			CreateFrame("GameTooltip","ccRTT",UIParent,"GameTooltipTemplate")
			ccRTT:SetOwner(UIParent,"ANCHOR_NONE")
		end
		----------------
		ccR_Frame:UnregisterEvent("ADDON_LOADED")
	end
	if event == "PLAYER_TALENT_UPDATE" then
			ccR.Sys.Default()
			ccR.GUI.Update()
		-- Empty Rotation, Set to 1st on list
		if ccR.Var("Rotation") == "Empty" and # DDM_List > 0 then UIDropDownMenu_SetSelectedID(DDM, 1) ccR.Var("Rotation", DDM_List[1])	end
	end
	if event == "SPELLS_CHANGED" then spellBook:Update() end
	if event == "PLAYER_ENTERING_WORLD" then
		ccR.Rotation.Stop()
	end
	if event == "LOOT_OPENED" then 
		ccR.Var("Auto_Loot_Pause", true) 
		ccR.Var("Auto_Target_Pause", true)
		vPauseStealth = true
	end
	if event == "LOOT_CLOSED" then
		ccR.Var("Auto_Loot_Pause", false)
		ccR.Var("Auto_Target_Pause", false)
		vPauseStealth = false
	end
	if event == "LFG_PROPOSAL_SHOW" then
		if FireHack then
			if ccR.Var("Use_Auto_LFG") then
				if not ccR.Var("Auto_LFG_NotInCombat") then	ccR_Timer.Register('AutoJoinLFG', ccR.Sys.JoinLFG, ccR.Var("Auto_LFG_Time")) end
				if ccR.Var("Auto_LFG_NotInCombat") then ccR_Timer.Register('AutoJoinLFG', ccR.Sys.JoinLFG, 1) end
			end
		end
	end
	if event == "LFG_PROPOSAL_HIDE" then
		ccR_Timer.Unregister('AutoJoinLFG')
	end
	if event == "UPDATE_BATTLEFIELD_STATUS" then
		if FireHack then
			if ccR.Var("Use_Auto_PVP") then
				if not ccR.Var("Auto_PVP_NotInCombat") then	ccR_Timer.Register('AutoJoinPVP', ccR.Sys.JoinPVP, ccR.Var("Auto_PVP_Time")) end
				if ccR.Var("Auto_PVP_NotInCombat") then ccR_Timer.Register('AutoJoinPVP', ccR.Sys.JoinPVP, 1) end
			end
		end
	end
	-- Cast Delay events
	if event == "PLAYER_REGEN_ENABLED" and type(ccR_CastDelay) == "table" then ccR_CastDelay = {} end
	if event == "UNIT_SPELLCAST_FAILED" or event == "UNIT_SPELLCAST_FAILED_QUIET" or event == "UNIT_SPELLCAST_INTERRUPTED" then
		local unitID, spell, rank, lineID, spellID = ...;
		if unitID == "player" then
			if type(ccR_CastDelay) == "table" then
				for thisGUID, thisSubTable in pairs(ccR_CastDelay) do
					if thisSubTable[1] == spell then ccR_CastDelay[thisGUID] = nil end
				end
			end
		end
	end
	if event == "COMBAT_LOG_EVENT_UNFILTERED" then
		local timestamp, event, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags, spellID, spellName, sSchool, fifteen, sixteen = ...;
		if event == "PARTY_KILL" or event == "UNIT_DIED" or event == "UNIT_DESTROYED" then
			if type(ccR_CastDelay) == "table" then
				for thisGUID, thisSubTable in pairs(ccR_CastDelay) do
					if thisGUID == destGUID then ccR_CastDelay[thisGUID] = nil end
				end
			end
		end
		if sourceGUID == UnitGUID("player") then
			if event == "SPELL_CAST_FAILED" or event == "SPELL_CAST_FAILED_QUIET" or event == "SPELL_INTERRUPT" or event == "SPELL_MISSED" or event == "SPELL_HEAL" or event == "SPELL_DAMAGE" or event == "SPELL_AURA_APPLIED" then
				if type(ccR_CastDelay) == "table" then
					for thisGUID, thisSubTable in pairs(ccR_CastDelay) do
						if thisGUID == destGUID and thisSubTable[1] == spellName then ccR_CastDelay[thisGUID] = nil end
					end
				end
			end
		end
	end
end